﻿Imports BUS
Imports DTO


Public Class MH_TuyChonBaoCaoBDHS

    Dim dsHS As New List(Of HocSinhDTO)

    Private Sub MH_TuyChonBaoCaoBDHS_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Load ds học sinh
        Dim hsBUS As New HocSinhBUS
        dsHS = hsBUS.LayDanhSach()
        dgvDanhSach.Rows.Clear()

        For i As Integer = 0 To dsHS.Count - 1
            dgvDanhSach.Rows.Add(i + 1, dsHS(i).HoTen, dsHS(i).GioiTinh, dsHS(i).NgaySinh)
        Next
    End Sub

    Private Sub btnHuy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHuy.Click
        Me.Close()
    End Sub

    Private Sub btnTim_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTim.Click
        Dim mh As New MH_TimKiemHocSinh()
        mh.ShowDialog()
        Try
            dsHS = mh.dgvDanhSach.DataSource
            dgvDanhSach.Rows.Clear()
            For i As Integer = 0 To dsHS.Count - 1
                dgvDanhSach.Rows.Add(i + 1, dsHS(i).HoTen, dsHS(i).GioiTinh, dsHS(i).NgaySinh)
            Next
        Catch ex As Exception

        End Try
    End Sub

    Private Sub btnLayBaoCao_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLayBaoCao.Click

        If (dgvDanhSach.CurrentRow IsNot Nothing) Then
            Dim index As Integer = dgvDanhSach.CurrentRow.Index

            'Khởi tạo báo cáo
            Dim bc As New BC_BangDiemHocSinh()
            Dim tbCurrent As CrystalDecisions.CrystalReports.Engine.Table
            Dim tliCurrent As CrystalDecisions.Shared.TableLogOnInfo
            For Each tbCurrent In bc.Database.Tables
                tliCurrent = tbCurrent.LogOnInfo
                With tliCurrent.ConnectionInfo
                    .ServerName = Application.StartupPath + "\0865059_0865125_QuanLiHocSinh.mdb"
                    '.UserID = "" 
                    '.Password = "" 
                    '.DatabaseName = "" 
                End With
                tbCurrent.ApplyLogOnInfo(tliCurrent)
            Next tbCurrent
            'Truyền tham số vào báo cáo: Mã lớp và tên lớp
            bc.SetParameterValue("Para_MaHocSinh", dsHS(index).MaHocSinh)
            bc.SetParameterValue("Para_TenHocSinh", dsHS(index).HoTen.ToUpper)
            bc.SetParameterValue("Para_GioiTinh", dsHS(index).GioiTinh)
            bc.SetParameterValue("Para_NgaySinh", dsHS(index).NgaySinh.ToShortDateString)
            'Khởi tạo màn hình hiển thị báo cáo
            Dim mh As New MH_InBaoCao()
            mh.crvBaoCao.ReportSource = bc
            mh.Show()

            Me.Close()
        End If

    End Sub
End Class